package com.gxa.medical.controller;

import com.gxa.medical.pojo.Activity;
import com.gxa.medical.service.ActivityHTService;
import com.gxa.medical.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/activityht")
@Api("患疗活动相关api接口")
@CrossOrigin
public class ActivityHTController {
    @Autowired
    private ActivityHTService activityHTService;

    @PostMapping("/all")
    @ApiOperation(value = "分页查询全部探讨的方法")
    public Map selectAllByPage(Integer page,Integer size){
        JsonResult jsonResult = new JsonResult();
        List<Map<String, Object>> maps = activityHTService.selectAllByPage(page, size);
        Integer integer = maps.size();
        Map map = new HashMap<>();
        map.put("maps",maps);
        map.put("integer",integer);
        jsonResult.setCode("200");
        jsonResult.setData(map);
        return jsonResult.getResultMap();
    }
    @PostMapping("/like")
    @ApiOperation(value = "模糊查询的方法")
    public Map selectByLike(String name, String host, String regTime, String overTime, Integer isud, String liveTime, Integer page, Integer size){
        JsonResult jsonResult = new JsonResult();
        List<Map<String, Object>> maps = activityHTService.selectByLike(name, host, regTime, overTime, isud, liveTime, page, size);
        int size1 = maps.size();
        Map map = new HashMap();
        map.put("maps",maps);
        map.put("size",size1);
        jsonResult.setCode("200");
        jsonResult.setData(map);
        return jsonResult.getResultMap();
    }
    @PostMapping("/delect")
    @ApiOperation(value ="删除数据的方法")
    public Map delectById(Integer id) {
        JsonResult jsonResult = new JsonResult();
        activityHTService.delete(id);
        activityHTService.deleteAD(id);
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        return jsonResult.getResultMap();
    }
    @PostMapping("/sbi")
    @ApiOperation(value ="查询医生名字数据的方法")
    public Map selectByIm(){
        List<Map<String, Object>> maps = activityHTService.selectAllByim();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(maps);
        return jsonResult.getResultMap();
    }
    @PostMapping("/insert")
    @ApiOperation(value ="添加数据的方法")
    private Map insert(String name,Activity activity){
        JsonResult jsonResult = new JsonResult();
        activityHTService.insert(activity);
        Integer act_id = activity.getAid();
        Integer doc_id = activityHTService.selectByDocName(name);
        activityHTService.insertAD(act_id,doc_id);
        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");
        return jsonResult.getResultMap();
    }
    @PostMapping("/update")
    @ApiOperation(value ="修改数据的方法")
    private Map update(Integer aid,String name,Activity activity){
        JsonResult jsonResult = new JsonResult();
        activityHTService.insert(activity);
        Integer act_id = activity.getAid();
        Integer doc_id = activityHTService.selectByDocName(name);
        activityHTService.insertAD(act_id,doc_id);
        activityHTService.delete(aid);
        activityHTService.deleteAD(aid);
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        return jsonResult.getResultMap();
    }
    @PostMapping("/xq")
    @ApiOperation(value = "详细查询方法")
    public Map selectByI(Integer id){
        JsonResult jsonResult = new JsonResult();
        Activity activity = activityHTService.selectByAid(id);
        jsonResult.setCode("200");
        jsonResult.setData(activity);
        return jsonResult.getResultMap();
    }
    @PostMapping("/lxq")
    @ApiOperation(value = "详情查询列表的方法")
    public Map selectById(Integer id){
        JsonResult jsonResult = new JsonResult();
        List<Map<String, Object>> maps = activityHTService.selectByUid(id);
        int size = maps.size();
        Map map = new HashMap();
        map.put("maps",maps);
        map.put("size",size);
        jsonResult.setCode("200");
        jsonResult.setData(map);
        return jsonResult.getResultMap();
    }
}
